﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMS.IRepository;


namespace CMS.Repository
{
    public class CourseDetailRepository : ICourseDetailRepository
    {
        /// <summary>
        /// Inserts the course details.
        /// </summary>
        /// <param name="cd">The cd.</param>
        public void InsertCourseDetails(Model.CourseDetails cd)
        {
            using (var edm = new CMSEntities())
            {
                CourseDetail coursedetails = Translator.CourseDetailTranslator.ToCourseDetailsEF(cd);
                edm.CourseDetails.AddObject(coursedetails);
                edm.SaveChanges();
            }

        }
        /// <summary>
        /// Deletes the course details.
        /// </summary>k
        /// <param name="cID">The c ID.</param>
        public void DeleteCourseDetails(int cID)
        {
            using (var edm = new CMSEntities())
            {
                var coursedetails = (from c in edm.CourseDetails
                                     where c.CourseId == cID
                                     select c).ToList<CourseDetail>();

                foreach (CourseDetail obj in coursedetails)
                {
                    edm.DeleteObject(obj);

                }
                edm.SaveChanges();

            }
        }
    }

}
